<template>
  <el-container style=" height:calc(100% - 5px);">
    <el-header class="common-header" style="height:80px;">
      <el-container>
        <el-aside width="590px">
          <h1 style="color: #15428F; font-size: 24pt; font-family: 华文琥珀;line-height:80px;">{{sysName}}</h1>
        </el-aside>
        <el-main style="text-align:right; padding:0 20px;">
          <div style="font-size: 14px; color: rgb(23, 56, 91);line-height:30px;padding-top:15px;">系统当前版本号： V1.6.0723 </div>
          <div class="common-h-link"><span>系统帮助</span><span>锁定系统</span><span>密码修改</span><span @click="logout()">注销用户[ {{sysUserName}} ]</span>
          </div>
        </el-main>
      </el-container>
    </el-header>
    <el-container class="common-content"  style="height:100%;" >
      <!--左侧菜单搜索-->
      <el-aside width="200px" style="height:100%;" class="asizebox" v-if="!collapsed">
        <el-container style="height:100%">
          <el-header style="padding:0;height:74px" >
            <div class="aside-tit">导航菜单</div>
            <div style="padding:5px;display: inline-flex;">
              <!-- <el-input
                placeholder="输入关键字搜索"
                v-model="form.test">
              </el-input> -->
              <el-input placeholder="输入关键字搜索"  v-model="form.test">
              <i class="el-icon-search icon-click" @click="searchMenu" style="margin-left:-20px;"></i>
                <el-button slot="append" icon="el-icon-search"></el-button>
              </el-input>
            </div>
          </el-header>
          <el-main style="height:calc(100% - 84px)">
            <!-- <el-menu class="el-menu-vertical-demo"
            :default-active="'/'+defaultActive"
            background-color="#1e374a"
            text-color="#eee" active-text-backgroundColor="#0ea3ca"
            active-text-color="#fff"
            unique-opened
            :collapse="collapsed" @select="handleselect"
            router
            > -->
            <el-menu class="el-menu-vertical-demo"
            :default-active="'/'+defaultActive"
            background-color="#cfe8fc"
            text-color="#15428F" active-text-backgroundColor="#99bbe8"
            active-text-color="#15428F"
            unique-opened
            :collapse="collapsed" @select="handleselect"  router>
            <!--左侧组件-->
            <navside :navlist="navlist"
            @select="handleselect" 
            router 
            ></navside>
            </el-menu>
          </el-main>
        </el-container>
      </el-aside>
      <el-main class="mainbox" style="height:100%;">
        <div class="nav-tab flex-div">
          <i :class="!collapsed?'el-icon-s-fold animation3':'el-icon-s-unfold animation3'"  @click.prevent="collapse" :title="!collapsed?'收起侧边框':'展开侧边框'" style="color:#15428F;font-size:1.5em;cursor:pointer;"></i>	
          <template v-if="showOtherRouter">
            <span @click="jumpRouter(true)">我的桌面</span>
            <span class="active" v-if="showOtherRouter">{{otherRoutername}}</span>
          </template>
          <template v-else>
            <span class="active">我的桌面</span>
            <span @click="jumpRouter(false)">{{otherRoutername}}</span>
          </template>
          
          
          <!-- <template v-if="currRoutername">
            <span class="active">我的桌面</span>
          </template>
          <template v-else>
            <span @click="goDesktop">我的桌面</span>
            <span class="active">{{otherRoutername}}</span>
          </template> -->
          
        </div>
        <div style="height:calc(100% - 33px);overflow:auto;">

          <el-scrollbar style="height:100%;">
            <router-view/>
            <!-- <transition name="fade" mode="out-in" style="height:100%;">
              <router-view style="height:100%;"></router-view>
            </transition> -->
          </el-scrollbar>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import {menuData} from '@/ajax/data'
import {LoginApi} from '@/ajax'
import navside from '@/components/NavSide'
export default {
  data(){
    return {
      form:{
        test:''
      },
      sysName:'西安市出租汽车企业在线业务管理系统',
      sysUserName:'',
      collapsed:false,
      navlist:[],
      prevRoutername:'',
      currRoutername:'',
      historyPath:'',
      handJump:false
    }
  },
  components:{
      navside
  },
  computed:{
    defaultActive(){
      
      return this.$route.path.slice(1);
    },
    otherRoutername(){  
      this.currRoutername = this.$route.matched[1].name;    
      this.currPath = this.$route.path;

      return this.handJump && this.$route.matched[1].name =='我的桌面' ? this.prevRoutername : this.$route.matched[1].name;
      //return  this.$route.matched;
    },
    showOtherRouter(){
      return this.handJump && this.$route.matched[1].name =='我的桌面' || this.$route.matched[1].name !='我的桌面';
    }    
  },
  mounted(){
    var user = sessionStorage.getItem('user');
    if (user) {
      user = JSON.parse(user);
      this.sysUserName = user.username || '';
    }
    this.navlist = menuData;

  },
  methods:{
    logout(){
      var _this = this;
      this.$confirm('确认注销吗?', '注销登录', {
        //type: 'warning'
      }).then(() => {
        LoginApi.requestLogout().then(result => {
          let { message, code, data } = result;
          if (code !== "10005") {
            _this.$message({
              message: '注销失败：'+message,
              type: 'error',
              duration:1500
            });
          } else {
            _this.$message({
              message: message,
              type: 'success',
              duration:'800',
              onClose:function (){
                sessionStorage.removeItem('user');
                _this.$router.push('/login');
              }
            });		
            
          }						
        }).catch(() => {
          _this.$message({
            message: '服务器异常，请稍后重试!',
            type: 'error',
            duration:1500
          });
        })
        
      }).catch(() => {

      });
    },
    collapse(){
      this.collapsed=!this.collapsed;
    },
    jumpRouter(STATE){
      if(STATE){
        this.prevRoutername = this.currRoutername;
        this.handJump = true;
        this.historyPath = this.currPath;
        setTimeout(()=>{
          this.$router.push({ path: '/home' })
        })
      }else{
        this.$router.push({ path: this.historyPath })
      } 
      
      
    },
    handleselect(a, b,c) {
      console.log("a:",a,"b:",b,"c:",c)
    },
    loadMenus(){
    },
    //搜索菜单
    searchMenu(){
      /* let menu = this.form.test;
      let arr = [];
      let k= 0;
      let r= 0;
      for(let i in  this.navlist){
        let child = this.navlist[i]['children'];
        for(let j in child){
          let name = String(child[j].name);
          console.log('menu',name.search(menu));
          if(name.search(menu) != -1){
            arr[r] = this.navlist[i];
            arr[r]['children'][k] = child[j];
            k++;
          }
        }
        //r++;
      }
      this.navlist = arr; */
    }
  }
}
</script>
<style scoped lang="scss">

$Color:#15428F;
$Bgnavtab:rgba(255,255,255,.5);
$BgHeader:#DFE8F6;
$BorderColor:#99bbe8;
.common-navstyle{
  color: $Color;font-weight: bold;line-height: 30px;border-radius: 3px;padding: 0 8px; background: linear-gradient(to bottom ,#fff,#deecfd,#fff); background-color:$Bgnavtab;
}
.common-header{
  background-color: $BgHeader;overflow: hidden;border-bottom:1px solid $BorderColor;
  .common-h-link{
    span{font-size: 12px;color:#444;margin-left:5px;line-height: 25px;cursor: pointer;
    &:hover{color: $Color}
    }
  }
}
.common-content{
  margin-top:5px;
  .asizebox{
    background-color:#cfe8fc;margin-right:5px;
    border: 1px solid $BorderColor;border-radius:3px;
    transition: width .5s;
    .aside-tit{border-bottom: 1px solid $BorderColor; @extend .common-navstyle }
  }
  .mainbox{
    background-color: #fff;
    border:1px solid $BorderColor;border-radius:3px;
    .tab-title{ line-height: 25px;background: linear-gradient(to bottom ,#deecfd,#c6d7ec);font-weight: bold;color: $Color;padding:5px;
      &>i{vertical-align: middle;margin-right:3px;}
    }

    .tab-content{padding:15px 20px;height:90px;
      .router-link{font-size: 16px;cursor: pointer;color: $Color; display: inline-block;min-width:150px;line-height:30px;height:30px;
        &:hover{text-decoration: underline;}
      }
    }
    .row-2-col{height:calc(50% - 78px);
      .el-col-12{height:100%;}
      .tab-box-border{border:1px solid $BorderColor;border-top:none;height:100%;
        .tab-title{border-top:2px solid $BorderColor;border-bottom:2px solid $BorderColor;}
        .tab-newslist{background-color: #fff;height:calc(100% - 39px);}
      }
    }
    .nav-tab{
      border-bottom:1px solid $BorderColor;padding-bottom:1px;
      span{@extend .common-navstyle;background: linear-gradient(to bottom ,#deecfd,#e8ecf1);cursor: pointer;display:inline-block;font-size:14px;border-bottom-right-radius:0;border-bottom-left-radius:0;margin-left:6px;width:20%;min-width:200px;max-width:300px;border:1px solid $BorderColor;font-weight:normal;background-color:#d1e2f8;border-bottom:0;
        &:hover,&.active{background: linear-gradient(to bottom ,#fff,#deecfd,#fff);color: $Color;font-weight: bold;background-color:#e0edfd;border-bottom:none;}
        &.active{cursor: default;}
      }
    }
  }
  .icon-click{
    margin-left: -30px;
    z-index: 20;
    line-height: 32px;
  }
	.animation3{transition: font-family 0.3s;}
}
</style>
